﻿
<!doctype html>
<html>
<head>
    <meta charset="utf-8" />
    <script src="/js/header.js"></script>
    <script src="/lib/date/wdatepicker.js"></script>
    <link href="/lib/easyui/default/easyui.css" rel="stylesheet" />
    <script type="text/javascript" src="/lib/easyui/jquery.easyui.min.js"></script>
</head>
<body>
    <div class="data-wrap case">
        <form class="form-inline" id="formSearch" onsubmit="return false;">
            <div class="data-tool clearfix">
                <div class="pull-left form-inline">
                    <a class="btn btn-default btn-sm export" href="javascript:void(0)" data-title="导出">导出</a>

                </div>
                <div class="pull-right">

                    <div class="input-group input-group-sm">
                        <label class="input-group-addon m5_l">银行卡号：</label>
                        <input class="form-control" name="cardNumber" type="text" autocomplete="off">
                    </div>

                    <div class="input-group">
                        <label class="input-group-addon m5_l">时间：</label>
                        <input id="d421" class="Wdate wd175" name="startTime" type="text" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss',maxDate:'%y-%M-%d'})" autocomplete="off" />--<input id="d422" class="Wdate wd175" name="endTime" type="text" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss',minDate:'#F{$dp.$D(\'d421\')}'})" autocomplete="off" />
                    </div>

                    <button type="button" class="btn btn-default btn-sm active" id="btnSearch"><span class="glyphicon glyphicon-search"></span> 搜索</button>

                </div>
            </div>
        </form>
        <div class="data-easyui data-scroll">
            <div class="data-view">
                <div class="data-div-view table-responsive">
                    <table class="easyui-treegrid" id="bankDetail"></table>
                </div>
            </div>
        </div>
    </div>
    <script src="/js/page/bankdetail.js?v=201903061350"></script>
    <script type="text/javascript">

        var pageSize = 50;

        $(function () {

            $("input[name='startTime']").val(FlashPay.Util.GetDateStr(-1) + " 00:00:00");
            $("input[name='endTime']").val(FlashPay.Util.GetDateStr(0) + " 23:59:59");

            $("#btnSearch").click(function () {

                window.currentPage = null;

                doSearch();
            });
            FlashPay.UI.DoSearch();

            $(".paymentRecordExport").click(function () {

                var query = {}

                query.startTime = $("input[name='startTime']").val();
                query.endTime = $("input[name='endTime']").val();

                var cardNumber = $("input[name='cardNumber']").val();
                if (!FlashPay.Util.isNullOrEmptySpance(cardNumber)) {
                    query.cardNumber = cardNumber;
                }

                FlashPay.UI.Confirm({
                    content: "下载付款记录需要花费大量时间,确认要下载吗？",
                    ok: function () {
                        var cover = FlashPay.UI.Mask({
                            obj: $("body"),
                            opacity: 0.5
                        });

                        FlashPay.Util.Ajax({
                            url: '/Payment/PaymentRecordExport',
                            type: 'POST',
                            data: { query: query },
                            success: function (response) {
                                if (response.success) {
                                    cover.Remove();

                                    if (response.data != null && response.data.length > 0) {
                                        var body = '<table>';

                                        $.each(response.data, function (i, item) {
                                            body += '<tr>';
                                            body += '<td>' + item.orderNo + '</td>';
                                            body += '<td>' + item.companyName + '</td>';
                                            body += '<td>' + item.withdrawalOrderNo + '</td>';
                                            body += '<td>' + item.bankName + '</td>';
                                            body += '<td>' + item.cardName + '</td>';
                                            body += '<td>' + item.cardNumber + '</td>';
                                            body += '<td>' + item.withdrawalAmount + '</td>';
                                            body += '<td>' + item.withdrawalFee + '</td>';
                                            body += '<td>' + item.createDbdate + '</td>';
                                            body += '<td>' + item.paymentStatus + '</td>';
                                            body += '<td>' + item.withdrawalAccountName + '</td>';
                                            body += '<td>' + item.withdrawalBankName + '</td>';
                                            body += '<td>' + item.withdrawalCardNumber + '</td>';
                                            body += '<td>' + item.paymentDate + '</td>';
                                            body += '<td>' + item.depositType + '</td>';
                                            body += '<td>' + item.noticeStatus + '</td>';
                                            body += '<td>' + item.noticeLastDate + '</td>';
                                            body += '<td>' + item.noticeTimes + '</td>';
                                            body += '<td>' + item.paymentType + '</td>';
                                            body += '</tr>';
                                        });

                                        body += '</table>';

                                        var excelFile = "<html xmlns:o='urn:schemas-microsoft-com:office:office' xmlns:x='urn:schemas-microsoft-com:office:excel' xmlns='http://www.w3.org/TR/REC-html40'>";
                                        excelFile += '<meta http-equiv="content-type" content="application/vnd.ms-excel; charset=UTF-8">';
                                        //excelFile += '<meta http-equiv="content-type" content="application/vnd.ms-excel';
                                        //excelFile += '; charset=UTF-8">';
                                        excelFile += "<head>";
                                        excelFile += "<!--[if gte mso 9]>";
                                        excelFile += "<xml>";
                                        excelFile += "<x:ExcelWorkbook>";
                                        excelFile += "<x:ExcelWorksheets>";
                                        excelFile += "<x:ExcelWorksheet>";
                                        excelFile += "<x:Name>";
                                        excelFile += "Sheet1";
                                        excelFile += "</x:Name>";
                                        excelFile += "<x:WorksheetOptions>";
                                        excelFile += "<x:DisplayGridlines/>";
                                        excelFile += "</x:WorksheetOptions>";
                                        excelFile += "</x:ExcelWorksheet>";
                                        excelFile += "</x:ExcelWorksheets>";
                                        excelFile += "</x:ExcelWorkbook>";
                                        excelFile += "</xml>";
                                        excelFile += "<![endif]-->";
                                        excelFile += "</head>";
                                        excelFile += "<body>";
                                        excelFile += body;
                                        excelFile += "</body>";
                                        excelFile += "</html>";

                                        var uri = window.URL.createObjectURL(new Blob([excelFile], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' }));//'data:application/vnd.ms-excel;charset=utf-8,' + encodeURIComponent(excelFile);
                                        var link = document.createElement("a");
                                        link.href = uri;

                                        link.style = "visibility:hidden";
                                        link.download = response.statusCode + ".xlsx";

                                        document.body.appendChild(link);
                                        link.click();
                                        document.body.removeChild(link);
                                    }
                                    else {
                                        cover.Remove();
                                        FlashPay.UI.Tip_short_warning("暂无记录");
                                    }

                                } else {
                                    cover.Remove();
                                    FlashPay.UI.Tip_short_warning("操作失败！" + response.errorMessage);
                                }
                            },
                            error: function (json) {
                                cover.Remove();
                                FlashPay.UI.Tip_warning("操作失败！请查看网络，请重试。");
                            }
                        });
                    }
                });

            });
        });

        $(document).keyup(function (event) {
            var keycode = event.which;
            if (keycode == 13) {
                FlashPay.UI.DoSearch();
            }
        });

        $.fn.serializeObject = function () {

            var o = {};

            var a = this.serializeArray();

            $.each(a, function () {
                if (o[this.name] !== undefined) {
                    if (!o[this.name].push) {
                        o[this.name] = [o[this.name]];
                    }
                    o[this.name].push(this.value || '');
                } else {
                    o[this.name] = this.value || '';
                }
            });

            return o;
        };
    </script>
</body>
</html>
